import 'package:flutter/material.dart';
import 'package:flutter_school/provider/index.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:provider/provider.dart';
import '../../http/index.dart';
import '../../public/repeat_fun.dart';

class MyPage extends StatefulWidget {
  MyPage({Key key}) : super(key: key);

  @override
  _MyPageState createState() => _MyPageState();
}

class _MyPageState extends State<MyPage> {
  @override
  Widget build(BuildContext context) {
    return Scaffold(
      body: Container(
        padding: EdgeInsets.fromLTRB(30.w, 100.h, 30.w, 0),
        child: Column(
          crossAxisAlignment: CrossAxisAlignment.start,
          children: [
            UserInfo(),
            SizedBox(height: 60.h),
            GoVip(),
            // Provider.of<GlobalData>(context).type == 4 ? GoVip() : '',
            SizedBox(height: 30.h),
            MyOption(),
          ],
        ),
      ),
    );
  }
}

class UserInfo extends StatefulWidget {
  UserInfo({Key key}) : super(key: key);

  @override
  _UserInfoState createState() => _UserInfoState();
}

class _UserInfoState extends State<UserInfo> {
  @override
  void initState() {
    super.initState();
  }

  userInfo(info) {
    return InkWell(
      child: Container(
        child: Row(
          mainAxisAlignment: MainAxisAlignment.spaceBetween,
          children: [
            Column(
              crossAxisAlignment: CrossAxisAlignment.start,
              mainAxisAlignment: MainAxisAlignment.center,
              children: [
                Text(Provider.of<GlobalData>(context).type == 3
                    ? info['data']['username']
                    : info['data']['name']),
                Text(info['data']['school']['name']),
              ],
            ),
            ClipOval(
              child: Image.network(
                Provider.of<GlobalData>(context).type == 3
                    ? info['data']['staff']['head_img'] == ''
                        ? 'https://ss1.bdstatic.com/70cFvXSh_Q1YnxGkpoWK1HF6hhy/it/u=3363295869,2467511306&fm=26&gp=0.jpg'
                        : info['data']['staff']['head_img']
                    : info['data']['head_img'] == ''
                        ? 'https://ss1.bdstatic.com/70cFvXSh_Q1YnxGkpoWK1HF6hhy/it/u=3363295869,2467511306&fm=26&gp=0.jpg'
                        : info['data']['head_img'],
                fit: BoxFit.fill,
                width: 100.w,
                height: 100.w,
              ),
            )
          ],
        ),
      ),
      onTap: () {},
    );
  }

  @override
  Widget build(BuildContext context) {
    return Container(
      alignment: Alignment.center,
      height: 125.h,
      child: RequertLoad(
          context, Http(context).postHttp('/auth/info', ''), userInfo),
    );
  }
}

class GoVip extends StatefulWidget {
  GoVip({Key key}) : super(key: key);

  @override
  _GoVipState createState() => _GoVipState();
}

class _GoVipState extends State<GoVip> {
  @override
  Widget build(BuildContext context) {
    return Container(
      padding: EdgeInsets.fromLTRB(0, 0, 30.w, 0),
      alignment: Alignment.centerRight,
      height: 150.h,
      decoration: BoxDecoration(
        color: Colors.black,
        border: Border.all(color: Colors.red),
      ),
      child: RaisedButton(
        color: Colors.white,
        shape: RoundedRectangleBorder(
            borderRadius: BorderRadius.all(Radius.circular(20))),
        child: Text(
          '立即开通',
          style: TextStyle(
            color: Colors.black,
          ),
        ),
        onPressed: () {
          Navigator.of(context).pushNamed('/payment_vip');
        },
      ),
    );
  }
}

class MyOption extends StatefulWidget {
  MyOption({Key key}) : super(key: key);

  @override
  _MyOptionState createState() => _MyOptionState();
}

class _MyOptionState extends State<MyOption> {
  @override
  Widget build(BuildContext context) {
    return Container(
      child: ListView(
        shrinkWrap: true,
        children: [
          ListTile(
            contentPadding: EdgeInsets.all(0),
            leading: ClipOval(
              child: Image.network(
                'https://ss0.bdstatic.com/70cFuHSh_Q1YnxGkpoWK1HF6hhy/it/u=2853553659,1775735885&fm=26&gp=0.jpg',
                width: 70.w,
                height: 70.w,
                fit: BoxFit.fill,
              ),
            ),
            title: Text("消息中心"),
            trailing: Icon(Icons.keyboard_arrow_right),
            onTap: () {
              print("消息中心");
            },
          ),
          ListTile(
            contentPadding: EdgeInsets.all(0),
            leading: ClipOval(
              child: Image.network(
                'https://ss0.bdstatic.com/70cFuHSh_Q1YnxGkpoWK1HF6hhy/it/u=2853553659,1775735885&fm=26&gp=0.jpg',
                width: 70.w,
                height: 70.w,
                fit: BoxFit.fill,
              ),
            ),
            title: Text("关于我们"),
            trailing: Icon(Icons.keyboard_arrow_right),
            onTap: () {
              print("关于我们");
            },
          ),
          ListTile(
            contentPadding: EdgeInsets.all(0),
            leading: ClipOval(
              child: Image.network(
                'https://ss0.bdstatic.com/70cFuHSh_Q1YnxGkpoWK1HF6hhy/it/u=2853553659,1775735885&fm=26&gp=0.jpg',
                width: 70.w,
                height: 70.w,
                fit: BoxFit.fill,
              ),
            ),
            title: Text("帮助中心"),
            trailing: Icon(Icons.keyboard_arrow_right),
            onTap: () {
              print("帮助中心");
            },
          ),
          ListTile(
            contentPadding: EdgeInsets.all(0),
            leading: ClipOval(
              child: Image.network(
                'https://ss0.bdstatic.com/70cFuHSh_Q1YnxGkpoWK1HF6hhy/it/u=2853553659,1775735885&fm=26&gp=0.jpg',
                width: 70.w,
                height: 70.w,
                fit: BoxFit.fill,
              ),
            ),
            title: Text("意见反馈"),
            trailing: Icon(Icons.keyboard_arrow_right),
            onTap: () {
              print("意见反馈");
            },
          ),
          ListTile(
            contentPadding: EdgeInsets.all(0),
            leading: ClipOval(
              child: Image.network(
                'https://ss0.bdstatic.com/70cFuHSh_Q1YnxGkpoWK1HF6hhy/it/u=2853553659,1775735885&fm=26&gp=0.jpg',
                width: 70.w,
                height: 70.w,
                fit: BoxFit.fill,
              ),
            ),
            title: Text("设置"),
            trailing: Icon(Icons.keyboard_arrow_right),
            onTap: () {
              Navigator.of(context).pushNamed('/setUp');
              print("设置");
            },
          )
        ],
      ),
    );
  }
}
